import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
import { CrudValidationGroups } from '@nestjsx/crud';
import {
  IsBoolean,


  IsOptional, IsString,


  ValidateNested
} from 'class-validator';
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { file } from './about/file';
import { BaseEntity } from './base.entity';
import { Group } from './group.entity';
import { Village } from './village.entity';

const { CREATE, UPDATE } = CrudValidationGroups;

@Entity()
export class ProjectConstruction extends BaseEntity {
  @ApiProperty({
    description: '项目建设主键',
    required: false,
  })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
    oneOf: [
      {
        type: 'Number',
      },
      {
        $ref: getSchemaPath(() => Village),
      },
    ],
  })
  @ManyToOne(
    () => Village,
    Village => Village.projectConstruction,
  )
  village: Number | Village;

  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
  })
  @ManyToOne(
    () => Group,
    Group => Group.projectConstruction,
    {
      eager: true,
    },
  )
  group: Number | Group;


  @ApiProperty({
    example: 1212,
    description: '项目编号',
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    nullable: true,
    type: "char",
    length: 255,
  })
  number: string;

  @ApiProperty({
    example: '项目建设名字',
    description: '项目建设名字',
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  name: string;

  @ApiProperty({
    example: true,
    description: '是否投标',
    required: true,
  })
  @IsBoolean({ always: true })
  @Column()
  bidding: boolean;

  @ApiProperty({
    example: true,
    description: '是否立项',
    required: true,
  })
  @IsBoolean({ always: true })
  @Column()
  projected: boolean;

  @ApiProperty({
    example: true,
    description: '是否招实施',
    required: true,
  })
  @IsBoolean({ always: true })
  @Column()
  implement: Boolean;

  @ApiProperty({
    example: '实施方',
    description: '实施方',
    required: true,
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    nullable: true,
    type: "char",
    length: 255,
  })
  implementer: string;

  @ApiProperty({
    example: '验收方',
    description: '验收方',
    required: true,
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true
  })
  acceptor: string;

  @ApiProperty({
    example: '监理方',
    description: '监理方',
    required: true,
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true
  })
  supervisor: string;

  @ApiProperty({
    example: '工程款支付情况',
    description: '工程款支付情况',
    required: true,
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "text",
    nullable: true
  })
  deliverySituation: string;

  @ApiProperty({
    example: '备注',
    description: '备注',
    required: true,
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: 'text',
    nullable: true
  })
  remarks: string;

  @ApiProperty({
    example: '相关文件',
    description: '相关文件',
    required: true,
  })
  @ValidateNested()
  @IsOptional({ always: true })
  @Column({
    type: "simple-json",
    nullable: true,
  })
  relatedDocuments: file[];
}
